<template>
	<view class="container">
		<view class="header">
			<image class="avatar" src="/static/logo.png"></image>
			<text class="username">{{ userInfo.phone || '用户姓名' }}</text>
		</view>
		
		<view class="menu-list">
			<view class="menu-item" @click="goToPersonalInfo">
				<text class="menu-text">个人信息</text>
				<text class="arrow">></text>
			</view>
			<view class="menu-item" @click="goToAccount">
				<text class="menu-text">账户信息</text>
				<text class="arrow">></text>
			</view>
			<view class="menu-item" @click="goToAccountManagement">
				<text class="menu-text">账号管理</text>
				<text class="arrow">></text>
			</view>
			<view class="menu-item" @click="goToVirtualNumber">
				<text class="menu-text">虚拟号管理</text>
				<text class="arrow">></text>
			</view>
			<view class="menu-item" @click="goToBilling">
				<text class="menu-text">账单查看</text>
				<text class="arrow">></text>
			</view>
			<view class="menu-item" @click="logout">
				<text class="menu-text logout-text">退出登录</text>
			</view>
		</view>
	</view>
</template>

<script>
	import websocket from '@/common/websocket.js'
	
	export default {
		data() {
			return {
				title: '个人中心',
				userInfo: {}
			}
		},
		onLoad() {
			// 从本地存储获取用户信息
			const userInfo = uni.getStorageSync('userInfo');
			if (userInfo) {
				this.userInfo = userInfo;
			}
		},
		methods: {
			logout() {
				// 清除用户信息
				uni.removeStorageSync('userInfo');
				
				// 断开WebSocket连接
				websocket.close();
				
				// 跳转到登录页面
				uni.redirectTo({
					url: '/pages/login/login'
				});
			},
			
			// 跳转到个人信息页面
			goToPersonalInfo() {
				uni.navigateTo({
					url: '/pages/profile/personalInfo'
				});
			},
			
			// 跳转到账户信息页面
			goToAccount() {
				uni.navigateTo({
					url: '/pages/profile/account'
				});
			},
			
			// 跳转到账号管理页面
			goToAccountManagement() {
				uni.navigateTo({
					url: '/pages/profile/accountManagement'
				});
			},
			
			// 跳转到虚拟号管理页面
			goToVirtualNumber() {
				uni.navigateTo({
					url: '/pages/profile/virtualNumber'
				});
			},
			
			// 跳转到账单页面
			goToBilling() {
				uni.navigateTo({
					url: '/pages/profile/billing'
				});
			}
		}
	}
</script>

<style>
	.container {
		padding: 20rpx;
	}
	
	.header {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 40rpx 0;
		background-color: #ffffff;
		border-radius: 10rpx;
		margin-bottom: 20rpx;
	}
	
	.avatar {
		width: 120rpx;
		height: 120rpx;
		margin-bottom: 20rpx;
	}
	
	.username {
		font-size: 36rpx;
		color: #333333;
		font-weight: bold;
	}
	
	.menu-list {
		background-color: #ffffff;
		border-radius: 10rpx;
		overflow: hidden;
	}
	
	.menu-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #f0f0f0;
	}
	
	.menu-item:last-child {
		border-bottom: none;
	}
	
	.menu-text {
		font-size: 30rpx;
		color: #333333;
	}
	
	.logout-text {
		color: #ff3b30;
	}
	
	.arrow {
		color: #c0c0c0;
	}
</style>